package com.sc.nft.dao;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.ActivityPropsConf;
import com.sc.nft.entity.UserEcologyHatchRecords;
import com.sc.nft.entity.vo.ecology.AdminEcologyRecycleRecordsVO;
import com.sc.nft.enums.ReceivedCollectionType;
import com.sc.nft.enums.UserEcologyHatchCollectionTypeRecordsEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserEcologyHatchCollectionRecords;
import com.sc.nft.mapper.UserEcologyHatchCollectionRecordsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 用户-生态-孵化-藏品记录表(sc_user_ecology_hatch_collection_records)数据DAO
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2023-10-18 14:32:54
 */
@Slf4j
@Repository
public class UserEcologyHatchCollectionRecordsDao extends ServiceImpl<UserEcologyHatchCollectionRecordsMapper, UserEcologyHatchCollectionRecords> {

    public Page<AdminEcologyRecycleRecordsVO> ecologyRecycleRecords(Page page, String collectionName, String numbering, String userTel, Integer integer, String beginTime, String endTime, Integer collectionStatus) {
        return baseMapper.ecologyRecycleRecords(page, collectionName, numbering, userTel, integer, beginTime, endTime, collectionStatus);
    }

    public Integer getCountByCollectionAndYesterday(Long confId, Long collectionId, UserEcologyHatchCollectionTypeRecordsEnum type, DateTime dateTime, DateTime dateTime1) {
        LambdaQueryWrapper<UserEcologyHatchCollectionRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserEcologyHatchCollectionRecords::getEcologyHatchId, confId);
        wrapper.eq(UserEcologyHatchCollectionRecords::getCollectionId, collectionId);
        wrapper.eq(UserEcologyHatchCollectionRecords::getType, type);
        wrapper.between(UserEcologyHatchCollectionRecords::getCreateTime, dateTime, dateTime1);
        return count(wrapper);
    }

    /**
     * 用户-生态-孵化-藏品记录（初始化 将熔炼记录ID记录）
     *
     * @param userId
     * @param ecologyHatchId
     * @param type
     * @param userEcologyHatchRecordsId
     * @return
     */
    public Boolean initialize(Long userId, Long ecologyHatchId, UserEcologyHatchCollectionTypeRecordsEnum type, Long userEcologyHatchRecordsId, Integer limitCount) {
        return baseMapper.initialize(userId, ecologyHatchId, type.getCode(), userEcologyHatchRecordsId, limitCount);
    }

    /**
     * 获取生态孵化下的回收或者销毁的藏品
     *
     * @param ecologyHatchId
     * @param type
     * @return
     */
    public List<UserEcologyHatchCollectionRecords> getList(Long ecologyHatchId, UserEcologyHatchCollectionTypeRecordsEnum type) {
        LambdaQueryWrapper<UserEcologyHatchCollectionRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserEcologyHatchCollectionRecords::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(UserEcologyHatchCollectionRecords::getType, type);
        return list(wrapper);
    }

    public Boolean initialize(List<Long> ids, Long userEcologyHatchRecordsId) {
        LambdaUpdateWrapper<UserEcologyHatchCollectionRecords> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(UserEcologyHatchCollectionRecords::getId, ids);
        wrapper.set(UserEcologyHatchCollectionRecords::getUserEcologyHatchRecordsId, userEcologyHatchRecordsId);
        return update(new UserEcologyHatchCollectionRecords(),wrapper);
    }

    public Integer getNumByTypeAndHatchId(UserEcologyHatchCollectionTypeRecordsEnum userEcologyHatchCollectionTypeRecordsEnum, Long ecologyHatchId) {
        return baseMapper.getNumByTypeAndHatchId(userEcologyHatchCollectionTypeRecordsEnum.getCode(),ecologyHatchId);
    }
}